package me.zhengjie.modules.system.domain

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import me.zhengjie.modules.system.service.dto.DeptDTO
import me.zhengjie.modules.system.service.dto.DictDTO
import jakarta.persistence.*
import org.apache.commons.lang3.builder.ToStringBuilder
import org.springframework.data.redis.core.RedisHash


/**
 * @author kuki
 * @date 2022-07-21
 */
@Entity
@Table(name = "sys_area")
@JsonTypeName("Area")
@RedisHash("area")
data class Area (
    // 序号
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    var id: Int? = null,

    // 区域名称
    @Column(name = "name", nullable = false)
    var name: String? = null,

    // 区域名称
    @Column(name = "name_chs", nullable = false)
    var nameChs: String? = null,

    // 区域名称
    @Column(name = "name_en", nullable = false)
    var nameEn: String? = null,

    // 区域代码
    //@Column(name = "area_code",nullable = false)
    //private Integer areaCode;
    // 城市代码
    @Column(name = "city_code", nullable = false)
    var cityCode: Long? = null
){
    annotation class Update
    companion object {
        fun fromJson(json: String): Area? {
            val obj=JacksonUtil.parseObject(json, Area::class.java)!!
            return when(obj){
                is Area -> obj
                else -> null
            }
        }
    }

    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }
    fun copy(source: Area?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}